]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
animationUtils: Use easeAsync() for wiggle
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 27 Nov 2025 10:28:23 +0000 (11:28 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Thu, 18 Dec 2025 16:33:25 +0000 (17:33 +0100)
The wiggle animation consists of 3 chained animations. This is
expressed a lot nicer with a series of async calls than nested
callbacks.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/4007>

js/misc/animationUtils.js

index cf6889609980d402ec4590cfaa0b745afded95c6..44d6e2fff4ac1d995785d2c883d8132e8c071c44 100644 (file)
@@ -2,6 +2,7 @@ import St from 'gi://St';
 import Clutter from 'gi://Clutter';
 
 import * as Params from './params.js';
+import {logErrorUnlessCancelled} from './errorUtils.js';
 
 const SCROLL_TIME = 100;
 
@@ -83,7 +84,7 @@ export function ensureActorVisibleInScrollView(scrollView, actor) {
  * @param {number} params.duration - the amount of time to move the actor per-wiggle
  * @param {number} params.wiggleCount - the number of times to wiggle the actor
  */
-export function wiggle(actor, params) {
+export async function wiggle(actor, params) {
     if (!St.Settings.get().enable_animations)
         return;
 
@@ -94,28 +95,30 @@ export function wiggle(actor, params) {
     });
     actor.translation_x = 0;
 
-    // Accelerate before wiggling
-    actor.ease({
-        translation_x: -params.offset,
-        duration: params.duration,
-        mode: Clutter.AnimationMode.EASE_OUT_QUAD,
-        onComplete: () => {
-            // Wiggle
-            actor.ease({
-                translation_x: params.offset,
-                duration: params.duration,
-                mode: Clutter.AnimationMode.LINEAR,
-                repeatCount: params.wiggleCount,
-                autoReverse: true,
-                onComplete: () => {
-                    // Decelerate and return to the original position
-                    actor.ease({
-                        translation_x: 0,
-                        duration: params.duration,
-                        mode: Clutter.AnimationMode.EASE_IN_QUAD,
-                    });
-                },
-            });
-        },
-    });
+    try {
+        // Accelerate before wiggling
+        await actor.easeAsync({
+            translation_x: -params.offset,
+            duration: params.duration,
+            mode: Clutter.AnimationMode.EASE_OUT_QUAD,
+        });
+
+        // Wiggle
+        await actor.easeAsync({
+            translation_x: params.offset,
+            duration: params.duration,
+            mode: Clutter.AnimationMode.LINEAR,
+            repeatCount: params.wiggleCount,
+            autoReverse: true,
+        });
+
+        // Decelerate and return to the original position
+        await actor.easeAsync({
+            translation_x: 0,
+            duration: params.duration,
+            mode: Clutter.AnimationMode.EASE_IN_QUAD,
+        });
+    } catch (e) {
+        logErrorUnlessCancelled(e);
+    }
 }